package com.cskaoyan.market.config;

import com.cskaoyan.market.filter.CharacterEncodingFilter;
import com.cskaoyan.market.filter.CrosFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.FilterRegistration;

/**
 * Created with IntelliJ IDEA 2021.
 * User: Lazarus_Liu
 * Date: 2023/8/7
 * Time: 17:21
 * Description:
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    // 注册filter
    @Bean
    public FilterRegistrationBean<OncePerRequestFilter> crosFilter(){
        FilterRegistrationBean<OncePerRequestFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new CrosFilter());
        return bean;
    }

    @Bean
    public FilterRegistrationBean<OncePerRequestFilter> characterFilter(){
        FilterRegistrationBean<OncePerRequestFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new CharacterEncodingFilter());
        return bean;
    }
}
